package com.wlyuan.open.remote.converter;

import com.alibaba.fastjson.JSON;
import com.wlyuan.open.remote.message.WaybillPickCovenantMessage;
import com.wlyuan.open.vo.push.waybill.WaybillPickCovenantDetailVO;
import lombok.var;

import java.time.LocalDateTime;

/**
 * @author
 * 提货预约消息转化器
 */
public class WaybillPickCovenantMessageConverter implements StringMessageConverter<WaybillPickCovenantMessage>{

    @Override
    public WaybillPickCovenantMessage convert(String source) {
        var message = JSON.parseObject(String.valueOf(JSON.parse(source)));
        WaybillPickCovenantDetailVO detail = new WaybillPickCovenantDetailVO();
        detail.setTenantId(message.getLong("tenantId"));
        detail.setUserId(message.getLong("userId"));
        var waybill = message.getJSONObject("waybill");
        detail.setOrderId(waybill.getLong("orderId"));
        detail.setOrderNo(waybill.getString("orderNo"));
        detail.setContractNo(waybill.getString("contractNo"));
        detail.setWaybillId(waybill.getLong("waybillId"));
        var pickCovenant = waybill.getJSONObject("pickCovenant");
        detail.setEnterTime(LocalDateTime.parse(pickCovenant.getString("arrivalTime")));
        detail.setMobile(pickCovenant.getString("contactMobile"));
        detail.setDriverName(pickCovenant.getString("driverName"));
        detail.setIdcard(pickCovenant.getString("idcard"));
        detail.setPlateNo(pickCovenant.getString("plateNo"));
        detail.setVehicleWeight(pickCovenant.getBigDecimal("vehicleLoad"));
        WaybillPickCovenantMessage pickMessage = new WaybillPickCovenantMessage();
        pickMessage.setCovenant(detail);
        return pickMessage;
    }
}
